package com.example.daohang;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class Fragment2 extends Fragment {
    private Button button;
    private Button button2;
    private Button button3;
    public Fragment2(){
        super(R.layout.fragment2);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        button = (Button) getView().findViewById(R.id.button);
        button2 = getView().findViewById(R.id.button2);
        button3 = getView().findViewById(R.id.button3);

        button.setText("打开百度");
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.setData(Uri.parse("https://www.baidu.com"));
                startActivity(intent);
                Toast.makeText(getActivity(),"打开百度",Toast.LENGTH_SHORT).show();
            }
        });

        button2.setText("打开BILIBILI");
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(getActivity().getPackageManager().getLaunchIntentForPackage("tv.danmaku.bili"));
            }
        });

        button3.setText("打开QQ");
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(getActivity().getPackageManager().getLaunchIntentForPackage("com.tencent.mobileqq"));
            }
        });
    }

}